package com.jiujichina.star.controller;

import com.jiujichina.base.Meta;
import com.jiujichina.base.ResultData;
import com.jiujichina.star.base.Account;
import com.jiujichina.star.service.AccountESService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/account")
@Api("AccountController相关的api")
public class AccountController {

	@Autowired
	AccountESService accountESService;

	//Logger logger = Logger.getLogger(AccountController.class);

	/**
	 * 根据ID查询用户
	 * @param id
	 * @return
	 */
	@ApiOperation(value="获取用户详细信息", notes="根据url的id来获取用户详细信息")
	@ApiImplicitParam(name = "searchContent", value = "搜索词", required = true, dataType = "String", paramType = "path")
	@RequestMapping(value = "/{searchContent}", method = RequestMethod.GET)
	public ResultData getUserById (@PathVariable(value = "searchContent") String  searchContent){
		 List<Account> list = accountESService.searchEntity(searchContent);
		return new ResultData(Meta.CODE_200.getCode(),list);
	}

	@ApiOperation(value="分页",notes = "分页")
	@RequestMapping(value = "/{queryName}/{num}/{size}", method = RequestMethod.GET)
	public ResultData queryByPage(@PathVariable String queryName,@PathVariable int num,@PathVariable int size){
		try{
			List<Account> accounts = accountESService.queryByPage(queryName,num,size);
			return new ResultData(Meta.CODE_200.getCode(),accounts);
		}catch(Exception e){
			e.printStackTrace();
		}
		return new ResultData();
	}



	
}
